/**
 *Project: jh-framework
 *File: cn.xkshow.lang.math.Probability.java 
 *Author: hardy(admin@xkshow.cn) Copyright
 ****************************************************************
 *   VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *    1.0        2013-7-4         hardy         create
 ****************************************************************
 *note: 
 ***************************************************************/ 
package cn.xkshow.lang.math;

import java.util.Random;

public class Probability {
	
	/*
	 * 从inputInt个数中产生outInt个随机数
	 * @return: 产生的随机数组
	 */
	public static int[] getRandArray(int inputInt, int outInt) {
		int[] aint = new int[inputInt];
		int[] bint = new int[outInt];
		for (int i = 0; i < inputInt; i++)// Array Init
		{
			aint[i] = i;
		}
		Random rnd = new Random();
		for (int i = 0; i < aint.length; ++i) {
			int iRnd = rnd.nextInt(aint.length);
			if (iRnd != i) // change
			{
				aint[i] = aint[i] + aint[iRnd];
				aint[iRnd] = aint[i] - aint[iRnd];
				aint[i] = aint[i] - aint[iRnd];
			}
		}

		for (int i = 0; i < outInt; i++) {
			bint[i] = aint[i];
		}

		return bint;
	}	
	public static String getRandStr(int inputInt, int outInt){
		int[] a = getRandArray(inputInt, outInt);
		StringBuilder sbui = new StringBuilder(",");
		for(int i=0;i<a.length;i++){
			sbui.append(a[i]+",");
		}
		return sbui.toString();
	}
	
}
